package com.example.mine_platform.controller.admin;

import com.example.mine_platform.commom.Result;
import com.example.mine_platform.pojo.dto.SchedulingLists;
import com.example.mine_platform.pojo.dto.SchedulingParam;
import com.example.mine_platform.service.SchedulingService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@CrossOrigin(origins = "*")
public class SchedulingController {
    @Resource
    SchedulingService schedulingService;
    @GetMapping("/user/busytime")
    public Result getOne(@RequestParam(value = "userId",required=true) int userId,
                         @RequestParam(value = "index",defaultValue="1") int index){
        int[][] list = schedulingService.getOne(userId,index);
        return Result.success(list);
    }
    @GetMapping("/admin/busytime")
    public Result getAll(@RequestParam(value = "index",defaultValue="1") int index){
        SchedulingLists list= schedulingService.getAll(index);
        return Result.success(list);
    }

    @PostMapping("/admin/busytime")
    public Result changeTime(@RequestBody SchedulingParam schedulingParam){
        System.out.println("sch,{}"+schedulingParam);
        int userId = schedulingParam.getUserId();
        int index = schedulingParam.getIndex();
        int day = schedulingParam.getDay();
        int time = schedulingParam.getTime();
        int status = schedulingParam.getStatus();
        schedulingService.changeTime(userId,index,day,time,status);
        return Result.success();
    }
}
